package com.qujia.station.controller;

import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.core.page.TableDataInfo;
import com.qujia.common.enums.BusinessType;
import com.qujia.station.domain.PayWay;
import com.qujia.station.domain.PayWayStationBetween;
import com.qujia.station.mapper.PayStationBetweenMapper;
import com.qujia.station.service.IPayStationBetweenService;
import com.qujia.station.service.IPayWayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 油站信息Controller
 *
 * @author qujia
 * @date 2020-12-08
 */
@RestController
@RequestMapping("/payWayBetween/info")
public class PayStationBetweenController extends BaseController
{
    @Autowired
    private IPayStationBetweenService payStationBetweenService;
    /**
     * 查询油站信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PayWayStationBetween payWayStationBetween)
    {
        startPage();
        List<PayWayStationBetween> tankList=payStationBetweenService.selectPayWayStationBetweenList(payWayStationBetween);
        return getDataTable(tankList);
    }

    /**
     * 获取支付方式的id信息
     */
    @GetMapping("/getStationPayInfo")
    public TableDataInfo getStationPayInfo(PayWayStationBetween payWayStationBetween)
    {
        List<PayWayStationBetween> tankList=payStationBetweenService.selectPayWayStationBetweenList(payWayStationBetween);
        List<Long> paylist=new ArrayList<>();
        for(PayWayStationBetween payWayStationBetween1:tankList){
            paylist.add(payWayStationBetween1.getPayWayId());
        }
        return getDataTable(paylist);
    }
    /**
     * 新增油品
     */
    @Log(title = "增加油站支付方式中间表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PayWayStationBetween payWayStationBetween)
    {

        return toAjax(payStationBetweenService.insertPayWayStationBetween(payWayStationBetween));
    }

    /**
     * 获取油站信息详细信息
     */
    @GetMapping(value = "/{payStationId}")
    public AjaxResult getInfo(@PathVariable("payStationId") Long payStationId)
    {
        PayWayStationBetween payWayStationBetween=payStationBetweenService.selectPayWayStationBetweenById(payStationId);

        return AjaxResult.success(payWayStationBetween);
    }

    /**
     * 修改油站信息
     */
    @Log(title = "修改支付方式油站中间表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PayWayStationBetween payWayStationBetween)
    {
        return toAjax(payStationBetweenService.updatePayWayStationBetween(payWayStationBetween));
    }



}
